import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

void main() => runApp(DrowpDownApp());

class DrowpDownApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HomePage(),
    );
  }
}

class PhoneItem {
  PhoneItem(this.id, this.name);
  final int id;
  final String name;
  static List<PhoneItem> getList() {
    return [
      PhoneItem(1, 'android'),
      PhoneItem(2, 'ios'),
      PhoneItem(3, 'fuchsia'),
      PhoneItem(4, 'harmoney'),
    ];
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  List phones = PhoneItem.getList();
  List<DropdownMenuItem<PhoneItem>> dropdowns;
  PhoneItem _item;
  @override
  void initState() {
    dropdowns = buildDropDownItems(phones);
    _item = dropdowns[0].value;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        centerTitle: true,
        title: Text('Materilal App Bar'),
      ),
      body: Center(
        child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              SvgPicture.asset(
                'asset/svg/android_iron_man.svg',
                width: 48.0,
              ),
              DropdownButton(
                isDense: true,
                elevation: 0,
                icon: Container(),
                underline: Container(),
                style: TextStyle(fontSize: 18.0, color: Colors.black),
                value: _item,
                items: dropdowns,
                onChanged: (PhoneItem item) {
                  setState(() {
                    _item = item;
                  });
                  print(item.name);
                },
              ),
              Text(_item.name)
            ]),
      ),
    );
  }

  List<DropdownMenuItem<PhoneItem>> buildDropDownItems(List phones) {
    List<DropdownMenuItem<PhoneItem>> list = List();
    for (PhoneItem item in phones) {
      list.add(DropdownMenuItem(value: item, child: Text(item.name)));
    }
    return list;
  }
}
